package com.hao.editorview.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hao.editorbox.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hao on 16/10/19.
 */
public class EmojiAdapter extends BaseAdapter {

    private List<String> emojiList;
    private Context context;


    public EmojiAdapter(Context context) {
        emojiList = new ArrayList<>();
        this.context = context;
    }


    public void setEmojiList(List<String> emojiList) {
        this.emojiList = emojiList;
    }

    @Override
    public Object getItem(int position) {
        return emojiList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getCount() {
        return emojiList.size();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(context).inflate(R.layout.emoji_text, null);
        TextView textView = (TextView) convertView.findViewById(R.id.emoji_item_text);
        ImageView imageView = (ImageView) convertView.findViewById(R.id.emoji_delete);
        if (position == emojiList.size() - 1) {
            if (imageView.getVisibility() == View.GONE)
                imageView.setVisibility(View.VISIBLE);
            if (textView.getVisibility() == View.VISIBLE)
                textView.setVisibility(View.GONE);
        } else {
            if (imageView.getVisibility() == View.VISIBLE)
                imageView.setVisibility(View.GONE);
            if (textView.getVisibility() == View.GONE)
                textView.setVisibility(View.VISIBLE);
            textView.setText(emojiList.get(position));
        }
        return convertView;
    }
}